import axios from "axios"
let exportFile = exportFile = (url, params, fileName) => {
    return new Promise((resolve, reject) => {
        axios({
            method: "POST",
            url: url,
            responseType: "blob",
            data: params
        }).then(d => {
            // resolve(res)
            let blob = new Blob([d.data], {
                type: "application/vnd.ms-excel"
            });
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var day = date.getDate();
            var hour = date.getHours();
            var minute = date.getMinutes();
            var second = date.getSeconds();
            date = year + "" + month + "" + day + "" + hour + "" + minute + "" + second; //'+date+'
            var downloadElement = document.createElement("a");
            var href = window.URL.createObjectURL(blob); //创建下载的链接
            downloadElement.href = href;
            downloadElement.download = fileName + date + ".xls"; //下载后文件名
            document.body.appendChild(downloadElement);
            downloadElement.click(); //点击下载
            document.body.removeChild(downloadElement); //下载完成移除元素
            window.URL.revokeObjectURL(href); //释放掉blob对象
        }).catch(err => {
            reject("导入失败原因"+err)
        })
    })

}
export {
    exportFile
}